package com.ict.txmsv2.controller.learnResource;

import com.ict.txmsv2.model.Encoded;
import com.ict.txmsv2.model.Exam;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.services.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yoleen
 * @date 2020/6/20 8:27
 */

@RestController
@RequestMapping("/resource/exam")
public class ExamController {
    @Autowired
    ExamService examService;

    @PostMapping("/")
    public RespBean getCourses(@RequestBody Encoded encoded){
        if(encoded==null || encoded.getCode().length()==0){
            return RespBean.error("查询失败！请输入正确的编码");
        }
//        System.out.println(encoded.getCode());
        List<Exam> ans = examService.getCoursesByEncoded(encoded.getCode());
        if (ans!=null && ans.size()>0){
            return RespBean.ok("查询成功！",ans);
        }
        return RespBean.error("查询失败！");
    }
}
